package com.robcity.platform.repo;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.robcity.platform.convert.RobotEventInfoConvert;
import com.robcity.platform.dto.RobotEventInfoSaveDTO;
import com.robcity.platform.dto.RobotLocationInfoSaveDTO;
import com.robcity.platform.entities.RobotEventInfo;
import com.robcity.platform.mapper.RobotEventInfoMapper;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description
 * @Author zhangsong
 * @Date 2024/8/10
 **/
@Component
public class RobotEventInfoRepo {
    @Resource
    RobotEventInfoMapper robotEventInfoMapper;

    public void insert(RobotEventInfoSaveDTO robotEventInfoDTO) {
        RobotEventInfo robotEventInfo = RobotEventInfoConvert.DTO2RobotEventInfo(robotEventInfoDTO);
        robotEventInfoMapper.insert(robotEventInfo);
    }

    public List<RobotEventInfo> selectRobotEventInfo(RobotLocationInfoSaveDTO robotLocationInfoDTO) {
        QueryWrapper<RobotEventInfo> queryWrapper = new QueryWrapper();
        queryWrapper.eq("rob_id", robotLocationInfoDTO.getRob_id())
                .eq("handel_status", "1")
                .eq("task_id", robotLocationInfoDTO.getTaskId());
        return robotEventInfoMapper.selectList(queryWrapper);

    }
    public List<RobotEventInfo> selectRobotEventInfo(){
        QueryWrapper<RobotEventInfo> queryWrapper = new QueryWrapper();
        queryWrapper.orderByDesc("create_time");
        return robotEventInfoMapper.selectList(queryWrapper);
    }

    public void RobotEventInfoClose(RobotLocationInfoSaveDTO robotLocationInfoDTO) {
        UpdateWrapper<RobotEventInfo> updateWrapper = new UpdateWrapper();
        updateWrapper
                .eq("task_id", robotLocationInfoDTO.getTaskId())
                .set("handel_status", "2");
        robotEventInfoMapper.update(null, updateWrapper);
    }
}
